/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package br.jm.mala.lazyModel;

import java.io.Serializable;
import java.util.List;
import javax.faces.model.ListDataModel;
import org.primefaces.model.SelectableDataModel;

/**
 *
 * @author joao
 * @param <T>
 */
public final class GenericDataModel<T> extends ListDataModel<T> implements SelectableDataModel<T>, Serializable {
    private static final long serialVersionUID = 800091408024450772L;

    public GenericDataModel() {
    }

    public GenericDataModel(List<T> data) {
        super(data);
    }
    
    @Override
    public Object getRowKey(T object) {
        return object.getClass();
    }

    @Override
    public T getRowData(String rowKey) {
        List<T> listEntidade = (List<T>) getWrappedData();
        
        for(T entidade : listEntidade) {
            if(entidade.getClass().equals(rowKey)) {
                return entidade;
            } else {
                return null;
            }
        }
        
        return null;
    }

}
